package com.my.spring.boot.ctrl;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;  
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;  
  
@Controller
public class HelloController 
{
	private Logger logger = Logger.getLogger(HelloController.class);
	 
    /*
    *   http://localhost:8080/hello?name=cn.7player
     */
 
    @RequestMapping("/hello")
//    public String greeting(Map<String,Object> map){
    public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
        logger.info("hello");
        model.addAttribute("hello", name);
//        map.put("hello","from TemplateController.helloHtml");  
        return"/hello";
    }
    
    @RequestMapping("/hello1")
    @ResponseBody
    public String hello(String name) {
        logger.info("hello");
        return "".equals(name)?"hello world!":null==name?"ni hao":name;
    }
}
